#include <iostream>
using namespace std;

class Integer {
public:
	Integer (int data = 0):m_data(new int(data)) {}
	~Integer (void) {
		cout << "析构函数" << endl;
		delete m_data;
	}
	void print (void) {
		cout << "*m_data=" << *m_data << endl; 
	}
	//自定义的拷贝构造函数 深拷贝
	Integer (const Integer& that) {
		m_data = new int (*(that.m_data));
	}
#if 0
	//类中有一个缺省的拷贝赋值操作符函数, 完成
	//两个对象之间的赋值操作 (浅拷贝)
	Integer& operator= (const Integer& that) {
		cout << "拷贝赋值函数" << endl;
		m_data = that.m_data;
		return *this;
	}
#endif
	//自己实现的深拷贝赋值函数
	Integer& operator= (const Integer& that) {
		cout << "深拷贝赋值" << endl;
		*m_data = *that.m_data;
		return *this;
	}

private:
	int *m_data;
};

int main (void)
{
	Integer i(1234);
	i.print ();
	
	Integer i2(i); //拷贝构造
	i2.print ();//1234

	Integer i3;
	i3 = i2; 
	i3.print ();
	return 0;
}
